package cn.tedu.charging.order.controller;

import cn.tedu.charging.common.pojo.JsonResult;
import cn.tedu.charging.order.pojo.param.OrderAddParam;
import cn.tedu.charging.order.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/order")
@Api(tags = "订单接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     * @param orderAddParam
     * @return
     */



    //RESTFul 定义接口的一个规范 ，基于http方法 GET POST PUT DELETE HEAD

    //订单
    //获取订单详情 GET /order/
    //删除订单    DEL /order/

    //Get 查询
    //POST  更新 新增 删除
    //获取订单详情 GET /order/{id}  /order?orderId=?
    //删除订单  POST  /del/order/{id}  /order/del/{id}    delOrderById
    //创建订单  POST  /add/order/{id}  /order/add/{id}    addOrder
    //更新订单  POST  /update/order/{id} /order/update/{id}  updateOrder

    //@PostMapping("create") 更新
    //@PutMapping("") 新
    //@GetMapping    读
    //@DeleteMapping 删
    //CRUD

    @ApiOperation("创建订单")
    @PostMapping("create")
    public JsonResult<String> createOrder(@RequestBody OrderAddParam orderAddParam) {
        //创建类型的接口是否返回出参,要根据业务来决定,如果后续的业务需要基于当前接口的出参(订单id)
        //做其他的操作,比如通过返回的出参(订单id),去查看订单详情,这个接口返回的订单id就是订单详情的入参
        String orderNo = orderService.createOrder(orderAddParam);
       /* JsonResult<String> result = new JsonResult<>();
        result.setCode(2000);
        result.setData(orderNo);
        return result;*/
        return JsonResult.ok(orderNo);
    }
}
